let map_div=document.createElement('div');
map_div.id='map'
map_div.style.height='880px'
document.body.insertAdjacentElement('afterbegin',map_div)


let town;
a=await  fetch('./json/town.json')
    .then((response) => response.json())
    // .then((town1) =>{return  town1});
    .then((town1) =>{
        town = town1;
        console.log(town1)  })

console.log(town)
// console.log(town)
// var map = L.map('map', {
//     center: [51.505, -0.09],
//     zoom: 0
// });

// L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
//     maxZoom: 19,
//     attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
// }).addTo(map);

// L.tileLayer('./pic/tiles/2/new/world_{x}_{y}.webp', {
//     maxZoom: 4,
//     // attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
// }).addTo(map);

L.TileLayer.Kitten = L.TileLayer.extend({
    getTileUrl: function({x,y,z}) {
        // const r = Math.pow(2, z)
        // const psize = 256 * Math.pow(2, z)
        // if (r + x > -1 && r + y > -1 && y < r && x < r) {
        //     //采用阿里图片裁剪，或者自己准备不同放大倍数下的对应图片素材
        //     return `https://www.baidu.com/test.jpg?x-oss-process=image/resize,w_${psize},h_${psize}/crop,x_${(r + x) * 256},y_${(r + y) * 256},w_256,h_256/format,jpg`
        // } else {
        //     //处理边界
        //     return 'https://www.baidu.com/test.jpg?x-oss-process=image/resize,p_25/crop,x_0,y_0,w_64,h_64/format,jpg'
        // }
        // console.log(x,y,z)

        return `./pic/tiles/new/${z}/world_${x}_${y}.webp`
    },
    options: {
        minZoom: 1,
        maxZoom: 3
    }
})
// 边界

const bounds = new L.LatLngBounds(new L.LatLng(-0, -0), new L.LatLng(0, 0))
const maxBounds = new L.LatLngBounds(new L.LatLng(-180, -180), new L.LatLng(180, 180))
L.CRS.Simple.transformation = new L.Transformation(1, -640.5, 1, -383)
const map = L.map('map', {//'map'是地图渲染的dom id，请给该dom设置宽高
    crs: L.CRS.Simple,//网格地图
    // attributionControl: false,
    // maxBounds: maxBounds,//地图边界
    // bounds: bounds,//地图坐标尺寸
    // maxBoundsViscosity: 0,//超出边界的表现
    // noWrap: true
}).setView([223, 653], 1) //居中展示，初始倍数为1倍图


//设置坐标点


var popup = L.popup();

function onMapClick(e) {
    popup
        .setLatLng(e.latlng)
        .setContent("You clicked the map at " + e.latlng.toString())
        .openOn(map);
}

map.on('click', onMapClick);

let bili=(4435/555.625+1774/221)/2;
console.log(bili)

var marker = L.marker([0,0]).addTo(map);
var marker1 = L.marker([1774/bili,4435/bili]).addTo(map);
var marker2 = L.marker([1851/bili,4519/bili]).addTo(map);
// var marker = L.marker([38.19,16.26]).addTo(map); // 鞋尖
// var marker1 = L.marker([37.34,11.55]).addTo(map); //突尖
// var marker1 = L.marker([41,20]).addTo(map);
// var marker2 = L.marker([0,0]).addTo(map);
//
L.tileLayer.kitten = function () {
    return new L.TileLayer.Kitten()
}

L.tileLayer.kitten().addTo(map)